﻿<UserControl x:Class="ScrumFactory.Tasks.TaskDetail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Tasks.Properties"
             xmlns:glob="clr-namespace:System.Globalization;assembly=mscorlib"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Adorners="clr-namespace:ScrumFactory.Windows.Helpers.Adorners;assembly=ScrumFactory.Windows.Helpers"             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             xmlns:SF_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             xmlns:KExt="clr-namespace:System.Windows.KExtensions;assembly=System.Windows.KExtensions"
             
             x:Name="thisView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
   
    
    <UserControl.Resources>
        <DataTemplate x:Key="TaskStatusDataTemplate">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Style="{StaticResource TaskStatusImage}"/>
                <TextBlock Grid.Column="1"
                           Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="TaskTypeDataTemplate">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Style="{StaticResource TaskTypeImage}" />
                <TextBlock Grid.Column="1" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <TabControl Style="{StaticResource WindowTabControl}">
        <TabControl.Items>
            <TabItem Header="{Binding PanelName}">
                <SF_Helpers:PanelLayout Title="{Binding PanelName}" Style="{StaticResource DetailPanelLayout}">

                    <!-- TOOLBAR -->
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>

                            <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                           
                            <MenuItem Header="{x:Static props:Resources.Finish_this_task}"
                                    Command="{Binding FinishTaskCommand}"
                                    Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}"
                                    ToolTip="{x:Static props:Resources.Finish_this_task}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/Buttons/check.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="{x:Static props:Resources.Copy_tag}"
                                    Command="{Binding CopyTaskTrackIdCommand}"
                                    Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}"
                                    ToolTip="{x:Static props:Resources.Copy_tag_tooltip}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/Toolbar/tag.png" Width="32" Height="32"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            
                            <MenuItem Header="{x:Static props:Resources.Change_log}" Command="{Binding ShowRepositoryLogCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/repfolder.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <ItemsControl Style="{StaticResource PluginMenuItems}" />

                        </ToolBar>
                    </SF_Helpers:PanelLayout.Toolbar>
                    
                    <SF_Helpers:PanelLayout.SubContent>
                        <Border Grid.Row="0" Grid.ColumnSpan="2" Background="{Binding BacklogItem.Group.GroupColor}" Margin="0,0,0,0" Height="45" Padding="0">
                            <Grid>

                                <TextBlock 
                                       Margin="29,-4,0,0" Padding="0" 
                                       HorizontalAlignment="Stretch" VerticalAlignment="Center"
                                       Background="{Binding BacklogItem.Group.GroupColor}"                                       
                                       Style="{StaticResource BacklogItemGroupTextBlock}"
                                        Text="{Binding BacklogItemAndGroupName}"/>

                                
                                    <ComboBox                                      
                                        HorizontalAlignment="Right" Background="White" VerticalAlignment="Center"                                                                           
                                        SelectedValue="{Binding Task_Status, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:TaskStatus}, UpdateSourceTrigger=PropertyChanged}"                        
                                        MinWidth="220"
                                        ItemTemplate="{StaticResource TaskStatusDataTemplate}"
                                        ItemsSource="{Binding Source={StaticResource TaskStatusList}}"/>
                                
                            </Grid>
                            
                        </Border>
                    </SF_Helpers:PanelLayout.SubContent>

                    <!-- CONTENT -->
                    <SF_Helpers:PanelLayout.Content>
                        <Grid VerticalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="160" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width=".3*" MinWidth="240" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>                                
                            </Grid.RowDefinitions>


                            <TextBlock                                       
                            Grid.Column="0" Grid.Row="1"
                            VerticalAlignment="Top"
                            Text="{x:Static props:Resources.Task}"
                            Style="{StaticResource LabelTextBlock}"/>

                            
                                <TextBox  
                                    KExt:SpellCheck.IsEnabled="True"
                                Grid.Column="1"  Grid.Row="1"                                                                
                                IsReadOnly="{Binding CanNotEditThisTask}"
                                HorizontalAlignment="Stretch" MaxLength="300" 
                                Text="{Binding Task.TaskName, UpdateSourceTrigger=PropertyChanged}"/>
                            



                            <TextBlock                                       
                            Grid.Column="0" Grid.Row="2" 
                            Text="{x:Static props:Resources.Task_type}"
                            Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
                                <ComboBox                                                    
                                    IsEnabled="{Binding CanEditThisTask}" MinWidth="220"
                                    HorizontalAlignment="Left"                                                                                
                                    SelectedValue="{Binding Task.TaskType, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:TaskTypes}, UpdateSourceTrigger=PropertyChanged}"                        
                                    ItemTemplate="{StaticResource TaskTypeDataTemplate}"
                                    ItemsSource="{Binding Source={StaticResource TaskTypeList}}"/>
                                <ToggleButton 
                                        ToolTip="{x:Static props:Resources.Payable}" 
                                        IsChecked="{Binding Task.IsAccounting}"                                       
                                        Style="{StaticResource CleanToggleButton}"
                                        VerticalAlignment="Center"
                                        Margin="10,0,0,0">                                    
                                        <Image Source="/Images/ToolBar/money.png" Width="24" Height="24" Stretch="Uniform"/>                                    
                                </ToggleButton>
                            </StackPanel>
                            


                            <TextBlock                                       
                                Grid.Column="0" Grid.Row="3"
                                Text="{x:Static props:Resources.Hours}"
                                Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal" IsEnabled="{Binding CanEditThisTask}">
                                <StackPanel>
                                    <TextBox Width="70" 
                                 SF_Ext:TextBoxExtension.AutoSelectOnFocus="True" SF_Ext:TextBoxExtension.NumericJumper="0.5"
                                 Text="{Binding Task.PlannedHours, StringFormat='{}{0:0.#}', UpdateSourceTrigger=PropertyChanged}" MaxLength="4" TextAlignment="Right" FontSize="{StaticResource ReallyBigFontSize}" FontWeight="Bold"/>
                                    <TextBlock Text="{x:Static props:Resources.Planned}" Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}" HorizontalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel>
                                    <TextBox Width="70" 
                                 SF_Ext:TextBoxExtension.AutoSelectOnFocus="True" SF_Ext:TextBoxExtension.NumericJumper="0.5"
                                 Text="{Binding TaskEffetiveHours, StringFormat='{}{0:0.#}', UpdateSourceTrigger=PropertyChanged}" MaxLength="4" TextAlignment="Right" FontSize="{StaticResource ReallyBigFontSize}" FontWeight="Bold"/>
                                    <TextBlock Text="{x:Static props:Resources.Real}" Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}"  HorizontalAlignment="Center"/>
                                </StackPanel>
                            </StackPanel>


                            <TextBlock                          
                            Grid.Column="0" Grid.Row="4"
                            Text="{x:Static props:Resources.started_at}"                        
                            Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="4" Orientation="Horizontal" IsEnabled="{Binding CanEditThisTask}">
                                
                                    <DatePicker SelectedDate="{Binding TaskStartDate, UpdateSourceTrigger=PropertyChanged}" />
                                    <TextBlock Text="{x:Static props:Resources.finished_at}" Style="{StaticResource LabelTextBlock}"/>
                                    <DatePicker SelectedDate="{Binding TaskEndDate, UpdateSourceTrigger=PropertyChanged}" />
                                
                            </StackPanel>

                            <TextBlock
                            Style="{StaticResource LabelTextBlock}"
                            FontSize="{StaticResource SmallFontSize}" FontStyle="Italic"
                            Grid.Column="1" Grid.Row="5">
                            <Run Text="{Binding Task.CreatedAt, StringFormat={x:Static props:Resources.created_at_N}}"/>
                            <Run Text="{Binding Task.TaskOwnerUId, StringFormat={x:Static props:Resources.by_N}}"/>
                            </TextBlock>

                            <TextBlock                                       
                                Grid.Column="0" Grid.Row="6"                                
                                Text="{x:Static props:Resources.Review_tag}"
                                Style="{StaticResource LabelTextBlock}"/>

                            <ComboBox
                                Grid.Column="1" Grid.Row="6" HorizontalAlignment="Left"
                                SelectedValuePath="TagUId" MinWidth="200"
                                DisplayMemberPath="Name"
                                SelectedValue="{Binding TagUId}"
                                ItemsSource="{Binding Tags}"/>

                            <TextBlock                                       
                                Grid.Column="0" Grid.Row="7"
                                VerticalAlignment="Top"
                                Text="{x:Static props:Resources.Description}"
                                Style="{StaticResource LabelTextBlock}"/>
                            <TextBox         
                                KExt:SpellCheck.IsEnabled="True"
                                Grid.Column="1"  Grid.Row="7"                                                                
                                IsReadOnly="{Binding CanNotEditThisTask}"
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
                                MaxLength="4000"
                                Text="{Binding TaskDetail, UpdateSourceTrigger=PropertyChanged}"/>
                                                           
                            <StackPanel
                                Grid.Column="2" Grid.RowSpan="8"
                                Orientation="Vertical">

                             

                                <TextBlock                                                                          
                                    Text="{x:Static props:Resources.Assignee}" 
                                    Style="{StaticResource ItemGroupTextBlock}"/>                                
                                <ComboBox                                                                       
                                    IsEnabled="{Binding CanChangeAssignee}" 
                                    Style="{StaticResource TaskAssigneeComboBoxWithImage}"                                    
                                    HorizontalAlignment="Center" MinWidth="60" MinHeight="60"
                                    SelectedValuePath="MemberUId" SelectedValue="{Binding TaskAssigneeUId}"
                                    ItemsSource="{Binding ProjectMembers}"/>
                                <TextBlock                                                                          
                                    Text="{x:Static props:Resources.as_}" HorizontalAlignment="Center"
                                    Style="{StaticResource LabelTextBlock}"/>                                
                                <ComboBox                                                    
                                    IsEnabled="{Binding CanChangeAssignee}" BorderBrush="Transparent" HorizontalAlignment="Center"
                                    MinWidth="100" Margin="0,0,0,0"
                                    DisplayMemberPath="RoleName"        
                                    SelectedValuePath="RoleUId"
                                    SelectedValue="{Binding Task.RoleUId}"                                                                    
                                    ItemsSource="{Binding ProjectRoles}"/>

                                <Button Command="{Binding ResetTaskAssigneeCommand}" Content="{x:Static props:Resources.Release}">
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding CanEditThisTask}" Value="False">
                                                    <Setter Property="Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>

                                <Separator HorizontalAlignment="Stretch" Height="2" Margin="10,10,0,10" />

                                <TextBlock                                                                          
                                    Text="{x:Static props:Resources.Priority}"  Margin="0,0,0,0"
                                    Style="{StaticResource ItemGroupTextBlock}"/>

                                <ComboBox                                                    
                                    BorderBrush="Transparent" Margin="0,0,0,0"
                                    HorizontalAlignment="Center" Width="100"      
                                    ItemsSource="{Binding Source={StaticResource PriorityTaskList}}"
                                    SelectedValue="{Binding Task.Priority, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:TaskPriorities}}">                                    
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Vertical">
                                                <Image DataContext="{Binding}" Style="{StaticResource PriorityIndicatorImage}" HorizontalAlignment="Center" />
                                                <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter}}" HorizontalAlignment="Center" FontSize="{StaticResource SmallFontSize}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>

                                <ContentPresenter                         
                                    Content="{Binding ArtifactListViewModel.View}"/>




                            </StackPanel>





                        </Grid>
                    </SF_Helpers:PanelLayout.Content>

                </SF_Helpers:PanelLayout>
            </TabItem>
           
        </TabControl.Items>
    </TabControl>

</UserControl>
